﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Beyond;
using System;
using UnityEngine.EventSystems;
using ZJ_WangSir;
using MyIdolUIFrameWork;

public class NewEvaluateBtn : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
    Button button;
    DateTime dt;
    // Use this for initialization
    void Start()
    {
        button = GetComponent<Button>();
        if (button != null)
        {
            button.onClick.AddListener(OnButtonClick);
        }

        bool timeBool = CPlayerPrefs.GetBool("time",false);
        if (!timeBool)
        {
            dt = Convert.ToDateTime(DateTime.Now.ToString());
            print(dt);
            CPlayerPrefs.SetLong("dt",dt.Ticks);
            CPlayerPrefs.SetBool("time", true);
        }

        int pjan = AppInfo.getSetting("pjan", 0,1);
        if (pjan == 0)
        {
            //button.GetComponent<Image>().enabled = false;
            gameObject.SetActive(false);
        }
        else if (pjan == 1)
        {
            TimeSpan tsdt = new TimeSpan(CPlayerPrefs.GetLong("dt"));
            TimeSpan nowdt = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan tsSub = tsdt.Subtract(nowdt).Duration();
            print(tsdt + "*-*-*-" + nowdt + "*--*-" + tsSub);
            print(tsSub.Days);
            if (tsSub.Days > 15)
            {
                //button.GetComponent<Image>().enabled = false;
                gameObject.SetActive(false);
            }
        }
        else if (pjan == 2)
        {
            //button.GetComponent<Image>().enabled = true;
            gameObject.SetActive(true);
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            ZJ_WangSir.CPlayerPrefs.RemoveKey("time");
            ZJ_WangSir.CPlayerPrefs.RemoveKey("dt");
        }

    }

    public void OnButtonClick()
    {
        //CSoundManager.s_aSounds["press_button"].Play();
        //CDialogPanel.Instance.OpenEvaluateDialog();
        //EvaluateAwardController.Instance.OpenEvaluateDialog();
        UIManager.Instance.SetVisible(UIName.UIEvaluate, true);
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        //gameObject.transform.localScale = new Vector2(0.9f, 0.9f);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        //gameObject.transform.localScale = new Vector2(1, 1);
    }

}
